# To change this template, choose Tools | Templates
# and open the template in the editor.

__author__="yangqibin"
__date__ ="$Nov 12, 2011 7:52:36 PM$"

import web
import res_code
import hashlib

db = web.database(dbn='mysql', db='blog', user='yangqibin', passwd='yangqibin', charset='utf8')

def login(username, password):
    db_res = db.select('member', where='username=$username', vars=locals())
    
    if not db_res:
        return res_code.err_no_such_user
    else:
        row = db_res[0]
#        print row.password, hashlib.md5(password).hexdigest()
        if row.password != hashlib.md5(password).hexdigest():
            return res_code.err_password_error
        else:
            return res_code.success

if __name__ == "__main__":
#    print hashlib.md5('12').hexdigest()
    res = login('test', '12')
    print res, res_code.get_extra_info(res)
    print login('test', '121')
    print login('test01', '12')
#
#    m = hashlib.md5()
#    m.update('12')
#    print m.digest()


